// @File  : struct.go
// @Author: JunLong.Liao&此处不应有BUG!
// @Date  : 2021/4/11
// @slogan: 又是不想写代码的一天，神兽保佑，代码无BUG！
//         ┏┓      ┏┓
//        ┏┛┻━━━━━━┛┻┓
//        ┃     ღ    ┃
//        ┃  ┳┛   ┗┳ ┃
//        ┃     ┻    ┃
//        ┗━┓      ┏━┛
//          ┃      ┗━━━┓
//          ┃ 神兽咆哮!  ┣┓
//          ┃         ┏┛
//          ┗┓┓┏━━━┳┓┏┛
//           ┃┫┫   ┃┫┫
//           ┗┻┛   ┗┻┛

package websocket

import (
	"github.com/gorilla/websocket"
	"sync"
)

// Manager 所有 websocket 信息
type Manager struct {
	IdClientMap                              map[int32]*Client
	Lock                                     sync.RWMutex
	MonitoringRealData, Register, UnRegister chan *Client
	Message                                  chan *MessageData
	GroupMessage                             chan *GroupMessageData
	BroadCastMessage                         chan *BroadCastMessageData
	incr                                     int32
}

var (
	// WebsocketManager 初始化 wsManager 管理器
	WebsocketManager = Manager{
		IdClientMap:        make(map[int32]*Client),
		Register:           make(chan *Client, 128),
		UnRegister:         make(chan *Client, 128),
		MonitoringRealData: make(chan *Client, 128),
		Message:            make(chan *MessageData, 128),
		GroupMessage:       make(chan *GroupMessageData, 128),
		BroadCastMessage:   make(chan *BroadCastMessageData, 128),
		incr:               1,
	}
	SystemId int32 = 1
)

// Client 单个 websocket 信息
type Client struct {
	Id        int32
	GroupList []int32
	Socket    *websocket.Conn
	Message   chan []byte
}

// messageData 单个发送数据信息
type MessageData struct {
	Id      int32
	Group   int
	Message []byte
}

// groupMessageData 组广播数据信息
type GroupMessageData struct {
	Group   int32
	Message []byte
}

// 广播发送数据信息
type BroadCastMessageData struct {
	Message []byte
}

// 读取消息
type ReadMessageRequest struct {
	Type     int    `json:"type"`
	Message  string `json:"message"`
	AcceptId int32  `json:"accept_id"`
}

// 消息返回
type MessageResponse struct {
	Status  int    `json:"status"`
	Type    int    `json:"type"`
	Message string `json:"message"`
	FromId  int32  `json:"from_id;"`
}
